<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<%--
  Created by Petro 18.11.12 15:15
--%>
<form:form method="POST" modelAttribute="registration">
    <tiles:insertDefinition name="editForm">
        <tiles:putAttribute name="title"><spring:message code="label.registration.title"/></tiles:putAttribute>
        <tiles:putAttribute name="description"><spring:message code="label.registration.description"/></tiles:putAttribute>
        <tiles:putAttribute name="data">
            <tiles:insertDefinition name="inputRow">
                <tiles:putAttribute name="path" value="email"/>
                <tiles:putAttribute name="label"><spring:message code="label.registration.email"/></tiles:putAttribute>
                <tiles:putAttribute name="required" value="true"/>
                <tiles:putAttribute name="data">
                    <form:input path="email"/>
                </tiles:putAttribute>
            </tiles:insertDefinition>
            <tiles:insertDefinition name="inputRow">
                <tiles:putAttribute name="path" value="confirmEmail"/>
                <tiles:putAttribute name="label"><spring:message code="label.registration.confirmEmail"/></tiles:putAttribute>
                <tiles:putAttribute name="required" value="true"/>
                <tiles:putAttribute name="data">
                    <form:input path="confirmEmail"/>
                </tiles:putAttribute>
            </tiles:insertDefinition>
            <tiles:insertDefinition name="inputRow">
                <tiles:putAttribute name="path" value="passwordForm.newPassword"/>
                <tiles:putAttribute name="label"><spring:message code="label.registration.regPassword"/></tiles:putAttribute>
                <tiles:putAttribute name="required" value="true"/>
                <tiles:putAttribute name="data">
                    <form:password path="passwordForm.newPassword"/>
                </tiles:putAttribute>
            </tiles:insertDefinition>
            <tiles:insertDefinition name="inputRow">
                <tiles:putAttribute name="path" value="passwordForm.confirmPassword"/>
                <tiles:putAttribute name="label"><spring:message code="label.registration.confirmPassword"/></tiles:putAttribute>
                <tiles:putAttribute name="required" value="true"/>
                <tiles:putAttribute name="data">
                    <form:password path="passwordForm.confirmPassword"/>
                </tiles:putAttribute>
            </tiles:insertDefinition>
            <tiles:insertDefinition name="inputRow">
                <tiles:putAttribute name="path" value="role"/>
                <tiles:putAttribute name="label"><spring:message code="label.registration.role"/></tiles:putAttribute>
                <tiles:putAttribute name="required" value="true"/>
                <tiles:putAttribute name="data">
                    <spring:message code='label.registration.role.INDIVIDUAL' var="labelIndividual"/>
                    <form:radiobutton path="role" value="INDIVIDUAL" label="${labelIndividual}"/>
                    <spring:message code='label.registration.role.AGENCY' var="labelAgency"/>
                    <form:radiobutton path="role" value="AGENCY" label="${labelAgency}"/>
                </tiles:putAttribute>
            </tiles:insertDefinition>
            <tiles:insertDefinition name="inputRow">
                <tiles:putAttribute name="path" value="nameForm.surName"/>
                <tiles:putAttribute name="label"><spring:message code="label.registration.surName"/></tiles:putAttribute>
                <tiles:putAttribute name="required" value="true"/>
                <tiles:putAttribute name="rowClass" value="changeableDisplay INDIVIDUAL"/>
                <tiles:putAttribute name="data">
                    <form:input path="nameForm.surName"/>
                </tiles:putAttribute>
            </tiles:insertDefinition>
            <tiles:insertDefinition name="inputRow">
                <tiles:putAttribute name="path" value="nameForm.firstName"/>
                <tiles:putAttribute name="label"><spring:message code="label.registration.firstName"/></tiles:putAttribute>
                <tiles:putAttribute name="required" value="true"/>
                <tiles:putAttribute name="rowClass" value="changeableDisplay INDIVIDUAL"/>
                <tiles:putAttribute name="data">
                    <form:input path="nameForm.firstName"/>
                </tiles:putAttribute>
            </tiles:insertDefinition>
            <tiles:insertDefinition name="inputRow">
                <tiles:putAttribute name="path" value="nameForm.patrName"/>
                <tiles:putAttribute name="label"><spring:message code="label.registration.patrName"/></tiles:putAttribute>
                <tiles:putAttribute name="rowClass" value="changeableDisplay INDIVIDUAL"/>
                <tiles:putAttribute name="data">
                    <form:input path="nameForm.patrName"/>
                </tiles:putAttribute>
            </tiles:insertDefinition>
            <tiles:insertDefinition name="inputRow">
                <tiles:putAttribute name="path" value="nameForm.name"/>
                <tiles:putAttribute name="label"><spring:message code="label.registration.name"/></tiles:putAttribute>
                <tiles:putAttribute name="required" value="true"/>
                <tiles:putAttribute name="rowClass" value="changeableDisplay AGENCY"/>
                <tiles:putAttribute name="data">
                    <form:input path="nameForm.name"/>
                </tiles:putAttribute>
            </tiles:insertDefinition>
            <div class="formRow">
                <div class="labelDiv">
                    <label for="recaptcha_response_field" class="label">
                        <spring:message code='label.registration.captcha'/><span class="asterisk">*</span>
                    </label>
                </div>
                <div class="valueDiv">${reCaptchaHtml}</div>
            </div>
            <div class="formRow">
                <button type="submit"><spring:message code='label.button.registration'/></button>
            </div>

            <script type="text/javascript">
                require(["dojo/query", "dojo/NodeList-dom"], function(query){
                    query("[name='role']").on("change", changeRole);
                    changeRole();
                    function changeRole() {
                        var roleRadio = query("[name='role']");
                        var role;
                        for (var i = 0; i < roleRadio.length; i++) {
                            if (roleRadio[i].checked) {
                                role = roleRadio[i].value;
                                break;
                            }
                        }
                        query(".changeableDisplay").style("display", "none");
                        query(".changeableDisplay input").attr("disabled", true);
                        query("."+role).style("display", "");
                        query("."+role+" input").attr("disabled", false);
                    }
                });
            </script>
            <style type="text/css">
                iframe {
                    display:none
                }
            </style>
        </tiles:putAttribute>
    </tiles:insertDefinition>
</form:form>